import { injectable } from "inversify";
import { BaseFormulaService } from "../base_class/BaseFormulaService";
import { SerializedNamedExpression } from "hyperformula";

@injectable()
export class FormulaService extends BaseFormulaService {
  constructor() {
    super();
  }
  getFunctionHelp(_functionName: string): string {
    return "No help available for this function";
  }

  addExpression(name: string, expression: string | number) {
    if (!this.hf.isItPossibleToAddNamedExpression(name, expression)) {
      this.hf.removeNamedExpression(name);
    }
    this.hf.addNamedExpression(name, expression);
  }

  removeExpression(name: string) {
    if (this.hf.isItPossibleToRemoveNamedExpression(name)) {
      this.hf.removeNamedExpression(name);
    }
  }
  listNamedExpression(): SerializedNamedExpression[] {
    // return this.hf.listNamedExpressions();
    return this.hf.getAllNamedExpressionsSerialized();
  }
  getExpression(name: string): string | undefined {
    const expression = this.hf.getNamedExpression(name);
    return expression?.expression;
  }

  // setArrayVariable(_value: any, _valueType: ValueType): string | undefined {
  //   const sheetId = this.hf.getSheetId(this.sheetName)!;
  //   const addr: SimpleCellAddress = {
  //     sheet: sheetId,
  //     col: _valueType,
  //     row: this.rowReadyForWrite[_valueType],
  //   };

  //   this.hf.setCellContents(addr, _value); // [[1],[2],[3]]
  //   this.rowReadyForWrite[_valueType] += _value.length;
  //   return BaseFormulaService.cellAddressToName(addr);
  // }
  // setMatrixVariable(_value: any, _valueType: ValueType): string | undefined {
  //   const sheetId = this.hf.getSheetId(this.sheetName)!;
  //   const addr: SimpleCellAddress = {
  //     sheet: sheetId,
  //     col: _valueType,
  //     row: this.rowReadyForWrite[_valueType],
  //   };

  //   this.hf.setCellContents(addr, _value); // [[1，1，1],[2，2，2],[3，3，3]]
  //   this.rowReadyForWrite[_valueType] += _value.length;
  //   return BaseFormulaService.cellAddressToName(addr);
  // }
}
